<!-- 基本信息设置 -->
<template>
    <div class="Information">
        <div class="Information_item">
            <div class="Information_item_top">节拍设置（s）</div>
            <div class="Information_item_button">
                <div>
                    节拍时间： &nbsp; &nbsp; &nbsp; &nbsp;<input type="number" v-model="Jptime" v-enter-number>
                </div>
            </div>
        </div>
        <div class="Information_item">
            <div class="Information_item_top">基础地址信息设置：</div>
            <div class="Information_item_button">
                <div>
                    <span> 产量地址： </span>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;PLC地址： <input type="text" v-model="yield_obj.addrPlc">
                </div>
                <div>
                    modbus地址： <input readonly type="text" v-model="yield_obj.addrModbus">
                </div>
                <div>
                    间隔： <input type="number" v-model="yield_obj.duration" v-enter-number>
                </div>
            </div>
            <div class="Information_item_button">
                <div>
                    <span>节拍地址： </span> &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;PLC地址： <input type="text" v-model="beat_obj.addrPlc">
                </div>
                <div>
                    modbus地址： <input readonly type="text" v-model="beat_obj.addrModbus">
                </div>
                <div>
                    间隔： <input type="number" v-model="beat_obj.duration" v-enter-number>
                </div>
            </div>
        </div>
        <div class="Information_item">
            <div class="Information_item_top">状态地址设置：</div>
            <div class="Information_item_button">
                <div>
                    <span>设备状态-维修：</span> PLC地址： <input type="text" v-model="repair_obj.addrPlc">
                </div>
                <div>
                    modbus地址： <input readonly type="text" v-model="repair_obj.addrModbus">
                </div>
                <div>
                    间隔： <input type="number" v-model="repair_obj.duration" v-enter-number>
                </div>
            </div>
            <div class="Information_item_button">
                <div>
                    <span>设备状态-停止：</span> PLC地址： <input type="text" v-model="stop_obj.addrPlc">
                </div>
                <div>
                    modbus地址： <input readonly type="text" v-model="stop_obj.addrModbus">
                </div>
                <div>
                    间隔： <input type="number" v-model="stop_obj.duration" v-enter-number>
                </div>
            </div>
            <div class="Information_item_button">
                <div>
                    <span>设备状态-待机：</span> PLC地址： <input type="text" v-model="bide_obj.addrPlc">
                </div>
                <div>
                    modbus地址： <input readonly type="text" v-model="bide_obj.addrModbus">
                </div>
                <div>
                    间隔： <input type="number" v-model="bide_obj.duration" v-enter-number>
                </div>
            </div>
            <div class="Information_item_button">
                <div>
                    <span>设备状态-运行：</span> PLC地址： <input type="text" v-model="run_obj.addrPlc">
                </div>
                <div>
                    modbus地址： <input readonly type="text" v-model="run_obj.addrModbus">
                </div>
                <div>
                    间隔： <input type="number" v-model="run_obj.duration" v-enter-number>
                </div>
            </div>
        </div>
        <button class="btn" @click="addclick">保存</button>
        <div class="zezaoc">
            <Btn_box />

        </div>
    </div>
</template>
<script>
import { getByEquipmentId, beatSetting, mesEquipment, addressByCode } from "@/api/SettingsApi/index.js"
import Btn_box from "@/components/uponelevel/index.vue"


export default {
    components: {
        Btn_box
    },
    data() {
        return {
            userID: "",
            Jptime: "",
            //产量
            yield_obj: {
                addrPlc: "",//地址id
                AddrCode: "CAPACITY",//地址编号
                equipmentId: this.$store.state.UserIndex.equipment.equipmentId,
                duration: "",//间隔单位秒S
            },
            //节拍
            beat_obj: {
                addrPlc: "",//地址id
                AddrCode: "BEAT",//地址编号
                equipmentId: this.$store.state.UserIndex.equipment.equipmentId,

                duration: "",//间隔单位秒S
            },
            //维修
            repair_obj: {
                addrPlc: "",//地址id
                AddrCode: "MAINTAIN",//地址编号
                equipmentId: this.$store.state.UserIndex.equipment.equipmentId,

                duration: "",//间隔单位秒S
            },
            //停止
            stop_obj: {
                addrPlc: "",//地址id
                AddrCode: "AWAIT",//地址编号
                equipmentId: this.$store.state.UserIndex.equipment.equipmentId,

                duration: "",//间隔单位秒S
            },
            // 待机
            bide_obj: {
                addrPlc: "",//地址id
                AddrCode: "STOP",//地址编号
                equipmentId: this.$store.state.UserIndex.equipment.equipmentId,

                duration: "",//间隔单位秒S
            },
            //运行
            run_obj: {
                addrPlc: "",//地址id
                AddrCode: "RUNNING",//地址编号
                equipmentId: this.$store.state.UserIndex.equipment.equipmentId,

                duration: "",//间隔单位秒S
            },


        }
    },
    mounted() {
        this.userID = this.$store.state.UserIndex.equipment.equipmentId
        this.getByfun(this.userID)
        this.beatfun(this.userID)
    },

    methods: {
        // 基本信息节拍设置
        addclick() {

            beatSetting({
                equipmentId: this.$store.state.UserIndex.equipment.equipmentId,
                defaultBeat: this.Jptime
            }).then(res => {
                console.log(res);
            })
            console.log(this.yield_obj);
            addressByCode([{
                addrPlc: this.yield_obj.addrPlc,
                addrCode: this.yield_obj.addrCode,
                equipmentId: Number(this.yield_obj.equipmentId),
                duration: this.yield_obj.duration
            }]).then(res => {

                console.log(res);
            })




            addressByCode(
                [{
                    addrPlc: this.beat_obj.addrPlc,
                    addrCode: this.beat_obj.addrCode,
                    equipmentId: Number(this.beat_obj.equipmentId),
                    duration: this.beat_obj.duration
                }]
            ).then(res => {
                console.log(res);
            })




            addressByCode(
                [{
                    addrPlc: this.repair_obj.addrPlc,
                    addrCode: this.repair_obj.addrCode,
                    equipmentId: Number(this.repair_obj.equipmentId),
                    duration: this.repair_obj.duration
                }]
            ).then(res => {
                console.log(res);
            })




            addressByCode(
                [{
                    addrPlc: this.stop_obj.addrPlc,
                    addrCode: this.stop_obj.addrCode,
                    equipmentId: Number(this.stop_obj.equipmentId),
                    duration: this.stop_obj.duration
                }]
            ).then(res => {
                console.log(res);
            })



            addressByCode(
                [{
                    addrPlc: this.bide_obj.addrPlc,
                    addrCode: this.bide_obj.addrCode,
                    equipmentId: Number(this.bide_obj.equipmentId),
                    duration: this.bide_obj.duration
                }]
            ).then(res => {
                console.log(res);
            })




            addressByCode(
                [{
                    addrPlc: this.run_obj.addrPlc,
                    addrCode: this.run_obj.addrCode,
                    equipmentId: Number(this.run_obj.equipmentId),
                    duration: this.run_obj.duration
                }]
            ).then(res => {
                console.log(res);
            })











        },
        getByfun(userID) {
            getByEquipmentId({
                equipmentId: userID
            }).then(res => {
                this.yield_obj = res.data[4]
                this.beat_obj = res.data[5]
                this.repair_obj = res.data[0]
                this.stop_obj = res.data[1]
                this.bide_obj = res.data[2]
                this.run_obj = res.data[3]
            })
        },
        beatfun(userID) {
            mesEquipment({
                id: userID
            }).then(res => {
                this.Jptime = res.data.defaultBeat
            })
        }
    }
}
</script>
<style lang="less" scoped>
.zezaoc {
    width: 106px;
    height: 30px;
    position: fixed;
    font-size: 10px;
    top: 80px;
    left: 1770px;

    display: flex;
    cursor: pointer;

    div {
        width: 98.38px;
            height: 40.38px;
            background: #031231;
            opacity: 1;
            text-align: center;
            line-height: 40.38px;
            color: white;
            margin: 0px 5px;


    }


}


.Information {
    width: 100%;
    height: 100%;
    color: white;
    font-size: 16px;

    .Information_item {
        width: 96%;
        padding: 19px 25px 2px 25px;
        font-size: 16px;


        .Information_item_top {
            height: 40px;
            line-height: 40px;
        }

        .Information_item_button {

            display: flex;
            margin-bottom: 10px;

            div:nth-child(2) {
                margin-left: 20px;
            }

            div:nth-child(3) {
                margin-left: 20px;
            }

            div {
                height: 100%;
                margin-right: .30px;
                font-family: SourceHanSansCN-Normal, SourceHanSansCN;
                font-weight: 400;
                color: #BDE5FD;
                line-height: 0px;
                font-size: 16px;

                span {
                    color: white;
                }

                input {
                    // margin-left: 20px;
                    width: 150px;
                    height: 40px;
                    outline: 0;
                    background: #031231;
                    border: 1px solid #5B9FC3;
                    color: white;
                }
            }
        }
    }

    .btn {
        width: 100px;
        height: 40px;
        border: 2px solid #113D71;
        background: none;
        color: white;
        margin: 24px;
        cursor: pointer;
    }
}
</style>